pkgname=vdr-sc
pkgver=0.6.2
pkgrel=1
arch=('i686')
pkgdesc="A software CAM emulation plugin for VDR"
url="http://207.44.152.197/plugin.htm"
license=('GPL')
backup=('etc/vdr/plugins/externalau.sh')
depends=('vdr' 'gcc' 'openssl')
source=(http://207.44.152.197/$pkgname-$pkgver.tar.gz vdr-sc-install.diff \
	vdr-sc-satbazaar.diff externalau.sh vdr-sc-newcamdhack.diff)
md5sums=('dc63fb6e86fa620d5c4cb6588e5bccec'
         '2cb70e48def7407a449e654f76b45b8d'
         'd41d1ab117d17a31a8a9c3ba13fe556e'
         '9e4085f351070a43e42e88ea05aaccd0'
         'b4074493b6afca0901d035fa4e5284a0')

build() {
  cd $startdir/src/sc-$pkgver

  patch -Np1 -i $startdir/src/vdr-sc-install.diff || return 1
  patch -Np1 -i $startdir/src/vdr-sc-satbazaar.diff || return 1
  sed -i 's/gbox.o/gbox.o satbazaar.o/' $startdir/src/vdr-sc-newcamdhack.diff
  patch -Np1 -i $startdir/src/vdr-sc-newcamdhack.diff || return 1
  sed -i "s:/include:/include -I/lib/modules/`uname -r`/build/include:" Makefile
  sed -i 's:^#define DEBUG_EXTERN::' data.c

  sed -i \
	 -e 's:-I$(VDRDIR)/include:-I$(VDRDIR):' \
	 -e 's:@cp -p $< $@:@install -D -m 755 $< $(DESTDIR)$@:' \
	 Makefile
  make VDRDIR=/usr/include/vdr LIBDIR=/usr/lib/vdr DESTDIR=$startdir/pkg all || return 1

  install -d $startdir/pkg/etc/vdr/plugins
  install -m 644 examples/*.{KID,Key,conf.example} $startdir/pkg/etc/vdr/plugins
  install -m 755 $startdir/src/externalau.sh $startdir/pkg/etc/vdr/plugins
}
